/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author antonio
 */

public class ICNN {
	int nLayers;
	CharSequence input;
	Layer layers[];
	int hierarchicalOrder[];
	int order;
	int n_neurons;
	
	public ICNN(int n, int ho[], int order)
	{
		this.nLayers = n;
		this.hierarchicalOrder = ho;
		this.order = order;
		this.layers = new Layer[this.nLayers];
		this.n_neurons = 0;
		for(int i = 0; i < this.nLayers; i++)
		{
			this.layers[i] = new Layer(this.hierarchicalOrder[i],this.order);
			this.layers[i].setLayer(i);
			this.n_neurons += this.hierarchicalOrder[i];
		}
	}
	
	public void feed(CharSequence feed) throws Exception
	{
		this.input = feed;
		this.layers[0].setInputStream(this.input);
		/*for(int i = 0; i < this.nLayers - 1; i++)
		{
			this.layers[i].assignInputToNode();
		}*/
	}
	
	public void evolve() throws Exception
	{
		for(int i = 0; i < this.nLayers; i++)
		{
			//System.out.println("layer: " + i);
			//this.layers[i].assignInputToNodeFuzzyStable();
			this.layers[i].assignInputToNode();
			//this.layers[i].assignInputToNodeSuperimposed();
			CharSequence feed = this.layers[i].outputStream();
			//System.out.println(feed);
			if(i != this.nLayers - 1)
			{
				this.layers[i+1].setInputStream(feed);
			}
		}
	}
	
	public CharSequence response() throws Exception
	{
		return this.layers[this.nLayers-1].outputStream();
	}
}
